<?php
    require "sql.php";
    $username = $_GET['username'];
    $filename = $_GET['filename'];
    $content='';
    $isPublic=0;
    $str="select * from file where author = '".$username."' and file_name = '".$filename."'";
    $result=$conn->query($str);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
           if($row['isPublic']==1||$username==$_COOKIE['username']){
                $isPublic=1;
                $content=$row['content'];
           }
        }       
    } 
    
    $conn->close();  
?>

<!doctype html>
<html>
<head>
    <meta charset="utf-8">

	<meta name="description" content="MarkDown简明语法在线编辑器实验">
	<meta name="keywords" content="HTML,CSS,JS,MARKDOWN,BOOTSTRAP">
	<meta name="author" content="zhonger">
	
	<title>MarkDown简明语法在线编辑器实验室</title>
    <link rel="icon" href="../../images/logo.ico">
    <!--Bootstrap样式引用-->
	<link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
    <script src="../../bower_components/jquery/dist/jquery.min.js"></script>
    <script src="../../bower_components/jquery.cookie/jquery.cookie.js"></script>
    <script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!--showdownjs样式引用-->
    <script src="../../bower_components/showdown/dist/showdown.min.js"></script>
    <!--highlight样式引用-->
    <link rel="stylesheet" href="../../bower_components/highlightjs/styles/default.css">
    <script src="../../bower_components/highlightjs/highlight.pack.js"></script>
    <!--自写样式-->

    
</head>
<body >

    <div class="container">
        <div class="row main">
            <div class="col-md-12">
                <acticle>
                    <h3>文件名：<?php echo $filename; ?>&nbsp;&nbsp;文件所有者：<?php echo $username; ?></h3><hr>
                    <form class="form">
                        <textarea id="code" name="code" hidden="hidden"><?php echo $content; ?></textarea>
                        <div class="html" id="browser"></div>
                        <input type="text" hidden="hidden" value="<?php echo $isPublic ?>" id="isPublic"/>
                    </form>
                </acticle>
                <script>
                    if($('#isPublic').val()==0){
                        var html="该文件为私密文件，如要阅读请联系文件所有者！";
                        $('#browser').html(html);
                    }else{
                         var converter = new showdown.Converter({
                            ghCodeBlocks: true,
                            headerLevelStart: false,
                            literalMidWordUnderscores: false,
                            noHeaderId: false,
                            omitExtraWLInCodeBlocks: true,
                            parseImgDimensions: false,
                            prefixHeaderId: false,
                            simplifiedAutoLink: true,
                            smoothLivePreview: false,
                            strikethrough: false,
                            tables: true,
                            tablesHeaderId: false,
                            tasklists: false
                        });
                        text = $('#code').val();
                        html = converter.makeHtml(text); 
                        $('#browser').html(html);
                        hljs.initHighlightingOnLoad();//语法高亮
                    }        
                </script>
            </div>
        </div>
    </div>
    <?php require "copy.html" ?>


</body>
</html>